1. Field of the Invention
The present invention relates to a method for interfacing floating point and integer processes in a computer system.
2. The Background Art
In modern computer systems, data may be represented in many ways, depending on the requirements of the process using the data. For example, there are several types of integer formats, two types of floating point formats (float and double), and boolean and character formats.
Integers are typically designated byte, short, int and long, representing 8, 16, 32, and 64 bit integers respectively. Although these terms are standard, other definitions may be assigned to these terms depending on what size the standard word size is on any given computer system.
Positive integer values are represented as the straight base 2 equivalent of the base 10 number. A negative number, instead of being represented by same magnitude with the sign bit set, is represented, in two's complement notation, as the binary number to which a positive number of the same magnitude is added to get zero. The two's complement of a number is found by "complementing" each binary digit (changing ones to zeros and zeros to ones) and then adding "1".
FIG. 1 is a diagram depicting the typical arrangement of a 32-bit integer in memory.
Referring to FIG. 1, a typical 32-bit integer value is represented as a sign bit 10, and a group of magnitude bits 12.
FIG. 2 is a diagram depicting the typical arrangement of a 32-bit floating point number in memory.
Referring to FIG. 2, a typical 32-bit floating point value is represented as a sign bit 14, exponent bits 16, and fractional bits 18.
With respect to floating point numbers, the term "float" typically refers to a 32-bit single precision number, and "double" refers to a 64-bit double precision number. However, 32-bit and 64-bit non-integer numbers are both generally classified as floating point numbers and will be referred to as such for the purposes of this disclosure. It is not the number of bits used when representing a number, or the way that number is described in memory, that classifies it as floating point. Rather, for the purposes of this disclosure, the term floating point will apply to any positive or negative real number.
In a normal computing session, it is common to have many different processes operating on data, occasionally swapping the data between those processes. In order to swap data between processes, the originating process must format the data in a way that is known by the receiving process. Thus, a floating point process which passes data to an integer process must convert the floating point data to integer format prior to passing the data.
Algorithms known in the art which interface floating point processes with integer-based processes, while useful for their intended purpose, often round a floating point number down to the next lower integer value, rather than rounding to the nearest integer. By rounding to the next lower integer rather than the nearest integer, the accuracy of the operation is reduced. It would therefore be beneficial to provide a method for interfacing a floating point-based process with an integer-based process which provides accurate conversion of the data between the two processes.